package com.qf.czh.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.czh.mapper.LogMapper;
import com.qf.czh.model.LoginLog;
import com.qf.czh.model.RespPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LogService {

    @Autowired
    LogMapper logMapper ;

    public RespPageBean getLogDataByPage(String page, String rows, String sort ,String order, String startTime, String endTime, String username, String type) {
        Map<String , Object> params = new HashMap<String, Object>();
        int p = Integer.parseInt(page);
        int r = Integer.parseInt(rows);
        params.put("page", page);
        params.put("rows", rows);
        params.put("sort" , sort);
        params.put("order", order);
        params.put("startTime", startTime);
        params.put("endTime", endTime);
        params.put("username", username);
        params.put("type", type);
        PageHelper.startPage(p,r);
        List<LoginLog> list = logMapper.getLogDataByPage(params);
        PageInfo<LoginLog> pageInfo = new PageInfo<LoginLog>(list);
        RespPageBean respPageBean = new RespPageBean();
        respPageBean.setTotal(pageInfo.getTotal());
        respPageBean.setRows(pageInfo.getList());

        return respPageBean;
    }
}
